package nsn.message.aggregator.model;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.HashSet;
import java.util.Set;

/**
 * 
 * @author Lukasz Nowak
 * @since 10-03-2011
 * 
 */
public abstract class AbstractMessageAggregator implements IMessageAggregator {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6057636025279796249L;
	final private Set<ISourceType> _types = new HashSet<ISourceType>();

	private final PropertyChangeSupport _propertySupport = new PropertyChangeSupport(
			this);

	@Override
	public Set<ISourceType> getSourceTypes() {
		return _types;
	}

	@Override
	public void update() {
		for (final ISourceType type : getSourceTypes()) {
			for (final ISource source : type.getSources()) {
				source.update();
			}
		}

	}

	@Override
	public void addPropertyChangeListener(PropertyChangeListener listener) {
		_propertySupport.addPropertyChangeListener(listener);

	}

	@Override
	public void removePropertyChangeListener(PropertyChangeListener listener) {
		_propertySupport.removePropertyChangeListener(listener);

	}

	/**
	 * @param event
	 */
	protected void firePropertyChange(final PropertyChangeEvent event) {
		_propertySupport.firePropertyChange(event);
	}
}
